package cn.krui.project.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import cn.krui.helper.bean.SysLoginInfo;
import cn.krui.helper.tools.JsonUtils;
import cn.krui.helper.tools.RedisUtils;
import cn.krui.helper.tools.WebToolsUtils;

/**
 * @author zc
 */
public class SystemBase {
	@Autowired
	private RedisUtils rUtils;

	/**
	 * 获得token
	 */
	public String getToken() {
		String token = WebToolsUtils.getRequest().getHeader("token");
		if (StringUtils.isEmpty(token)) {
			return "";
		} else {
			return token;
		}
	}

	/**
	 * 获取当前登录用户信息
	 */
	public SysLoginInfo getUser() {
		Object token = rUtils.get("login_token:" + getToken());
		SysLoginInfo sysUser = JsonUtils.toObject(token + "", SysLoginInfo.class);
		return sysUser;
	}

}